package com.gblw.rjkf.pj.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gblw.rjkf.pj.entity.TOrder;
import com.gblw.rjkf.pj.mapper.TOrderMapper;
import com.gblw.rjkf.pj.service.TOrderService;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * TOrderServiceImpl(TOrder)
 *
 * @author wj
 * @since 2024-09-24 19:07:48
 */
@Slf4j
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {


    @GlobalTransactional(name = "zzyy-crate-order",rollbackFor = Exception.class)
    public void creata(TOrder order){
        String xid = RootContext.getXID();
        log.info("----------------开始创建订单：xid:"+xid );
        order.setStatus(0);
        System.out.println("order:"+order.toString());
        int result = baseMapper.insert(order);
        TOrder order1 =null;
        if(result>0){
            order1 = baseMapper.selectById(order.getId());
            log.info("-------------->新建订单成功，order1 info:"+order1.toString());
            System.out.println();
            //2扣减库存
            log.info("-------------->订单微服务开始调用storage库存，做扣减count");

            log.info("-------------->订单微服务开始调用storage库存，做扣减完成");
            //3扣账户金额
            log.info("-------------->订单微服务开始调用Account账号，做扣减money");

            log.info("-------------->订单微服务开始调用Account账号，做扣减成功");
        }
    }
}
